//一个基于malloc()的练习
#include <stdio.h>
int* make_array(int elem, int val);
void show_array(const int ar[], int n);

int main(void)
{
	int* pa;
	int size;
	int value;

	printf("enter the number of elements: ");
	while (scanf_s("%d", &size, 4)==1&&size>0)
	{
		printf("enter the initialzation value:");
		scanf_s("%d", &value, 4);
		pa = make_array(size, value);
		if (pa)
		{
			show_array(pa, size);
			free(pa);
		}
		printf("enter the number of elements:(0 to quit)");
	}
	printf("done.\n");
	return 0;
}
int* make_array(int elem, int val)
{
	int* ptd;
	ptd = (int*)malloc(elem * sizeof(int));
	int i;
	for (i = 0; i <= elem - 1; i++)
		ptd[i] = val;
	return ptd;
}
void show_array(const int ar[], int n)
{
	int i;
	for (i = 0; i <= n - 1; i++)
		printf("%d\n", ar[i]);

}